﻿var Fantasy = {};

(function () {
    Fantasy.WatchList = function () {
        var _watchList = new List.PlayerList();
        var _playerList = new List.PlayerList();

        function constructor() {
            console.log("inn i funksjonen");
            var watchListSettings = {
                type: "POST",
                url: "WatchList.aspx/getWatchList",
                data: "{}",
                contentType: "application/json; charset=utf-8"
            };
            console.log("inn i funksjonen2")
            _watchList.populateList(watchListSettings, function() {
            $.ajax({
                type: "POST",
                url: "WatchList.aspx/getAllPlayers",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var playerList = JSON.parse(response.d);
                    for (var i = 0; i < playerList.length; i++) {
                        var id = playerList[i]["playerID"];
                        if (!(id in _watchList.getAllPlayers())) {
                            _playerList.addElement(playerList[i]);
                        }
                    }
                }
            });
            });
            console.log("inn i funksjonen2");

            
        };
        constructor();
        
        return {
            getWatchList: function() {
                return _watchList;
            },
            getPlayerList: function() {
                return _playerList;
            }
           
        };
    };
})();
